package com.javaweb.service.impl;

import com.javaweb.dao.CategoryDao;
import com.javaweb.model.Category;
import com.javaweb.service.CategoryService;
import com.javaweb.service.dto.CategoryDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

@Service
public class CategoryServiceImpl implements CategoryService {

    @Autowired
    private CategoryDao categoryDao;

    // 删除分类
    @Override
    public void deleteCategory(String categoryId) {
        categoryDao.deleteCategoryById(categoryId);
    }

    // 新增分类
    @Override
    public CategoryDto addCategory(CategoryDto categoryDto) {
        categoryDao.addCategory(categoryDto);
        return categoryDto;  // Returning the DTO after inserting
    }

    // 获取所有分类
    @Override
    public List<CategoryDto> listCategories() {
        return categoryDao.getAllCategories();
    }
}
